/**
 * Created with JetBrains WebStorm.
 * User: scb
 * Date: 25/4/13
 * Time: 10:51 AM
 * To change this template use File | Settings | File Templates.
 */

describe("MailboxComposeController",function(){
    var mailboxComposeController = null;
    var t_alertCtrl = null;
    var t_loadingCtrl = null;

    beforeEach(function(){
        //need feature
        t_alertCtrl = App.AlertController.create();
        t_loadingCtrl = App.LoadingController.create();
        App.MailboxComposeController.reopen({
            init:function(){
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
            }
        });
        mailboxComposeController = App.MailboxComposeController.create();
    });

    it("prepareController",function(){
        spyOn(App.apiMailBox, "getCategory").andCallFake(function(callback) {
            callback({});
        });
        spyOn(mailboxComposeController, "callbackCategory");
        
        mailboxComposeController.prepareController();
        
        expect(App.apiMailBox.getCategory).toHaveBeenCalled();
        expect(mailboxComposeController.callbackCategory).toHaveBeenCalledWith({}, undefined);
    });

    it("callbackCategory",function(){
        var response = {
            "configurationDataResponse" : {
                "configurationData" : {
                    "configurationList":[
	                    {valueList:[
	                        {code:{},value:{}},
	                        {code:{},value:{}},
	                        {code:{},value:{}},
	                        {code:{},value:{}}
	                    ]},
	                    {valueList:[
	                        {code:{},value:{}},
	                        {code:{},value:{}},
	                        {code:{},value:{}},
	                        {code:{},value:{}}
	                    ]}
                    ]
                }
            }
        };
        
        mailboxComposeController.callbackCategory(response.configurationDataResponse.configurationData.configurationList);
        
        expect(mailboxComposeController.categoryDropDownData.list.length).toBe(4);
    });
    
    it("sendMail",function(){
        spyOn(App.apiMailBox,"compose").andCallFake(function(data0,data ,data1,data2,callback) {
            callback({});
        });
        mailboxComposeController.categoryDropDownData.selectedItem = {value:{},code:{}};
        mailboxComposeController.toDropDownData.selectedItem = {value:{},code:{}};
        spyOn(mailboxComposeController,"callbackSend");
        mailboxComposeController.sendMail({});
        expect(App.apiMailBox.compose).toHaveBeenCalled();
    });

    it("callbackSend have error",function(){
    	spyOn(mailboxComposeController.get('controllers').get('alert'),"showAlert");
        mailboxComposeController.callbackSend({}, BreezeException.create());
        expect(mailboxComposeController.get('controllers').get('alert').showAlert).toHaveBeenCalledWith(App.i18n.getTranslations().get('mailbox.messageSentFailure'));
    });
    
    it("callbackSend not have error",function(){
        spyOn(mailboxComposeController.get('controllers').get('alert'),"showAlert");
        mailboxComposeController.callbackSend({});
        expect(mailboxComposeController.get('controllers').get('alert').showAlert).toHaveBeenCalledWith(App.i18n.getTranslations().get('mailbox.messageSentSuccess'),jasmine.any(Function));
    });

    it("isEmptyContent",function(){
        mailboxComposeController.categoryDropDownData.selectedItem = {code:"",value:""};
        mailboxComposeController.compose.subject = "";
        mailboxComposeController.compose.body = "";
        var result = mailboxComposeController.isEmptyContent();
        expect(result).toBe(false);
    });
});